package com.lingx.model.config;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.lingx.model.IExecutor;
import com.lingx.model.impl.DefaultMethod;
import com.lingx.model.impl.DefaultNode;
import com.lingx.model.impl.executor.ComboExecutor;
import com.lingx.model.impl.executor.GetExecutor;
import com.lingx.model.impl.executor.GridExecutor;
import com.lingx.model.impl.executor.TreeExecutor;

@Configuration
public class MethodConfig {
	@Resource
	private  ApplicationContext spring = null;
	//lingx/template/GridCascade
	@Bean
	public DefaultMethod gridBean() {
		DefaultMethod method=new DefaultMethod();
		method.setCode("grid");
		method.setName("表格数据");
		method.setValidation(false);
		method.setViewUri("/main/grid");
		method.setVisible(false);//工具栏不可见

		DefaultNode<IExecutor> node=new DefaultNode<IExecutor>("执行器");
		method.setExecutors(node);
		List<IExecutor> list=new ArrayList<>();
		list.add(spring.getBean(GridExecutor.class));//		private GridExecutor gridExecutor;
		node.setList(list);
		return method;
	}

	@Bean
	public DefaultMethod treeBean() {
		DefaultMethod method=new DefaultMethod();
		method.setCode("tree");
		method.setName("树形数据");
		method.setValidation(false);
		method.setViewUri("/main/tree");
		method.setVisible(false);//工具栏不可见

		DefaultNode<IExecutor> node=new DefaultNode<IExecutor>("执行器");
		method.setExecutors(node);
		List<IExecutor> list=new ArrayList<>();
		list.add(spring.getBean(TreeExecutor.class));//		private GridExecutor gridExecutor;
		node.setList(list);
		return method;
	}
	@Bean
	public DefaultMethod gridCascadeBean() {
		DefaultMethod method=new DefaultMethod();
		method.setCode("grid_cascade");
		method.setName("表格级联");
		method.setValidation(false);
		method.setViewUri("/main/gridcascade");
		method.setVisible(false);//工具栏不可见

		DefaultNode<IExecutor> node=new DefaultNode<IExecutor>("执行器");
		method.setExecutors(node);
		List<IExecutor> list=new ArrayList<>();
		list.add(spring.getBean(GridExecutor.class));//		private GridExecutor gridExecutor;
		node.setList(list);
		return method;
	}

	@Bean
	public DefaultMethod treeCascadeBean() {
		DefaultMethod method=new DefaultMethod();
		method.setCode("tree_cascade");
		method.setName("树形级联");
		method.setValidation(false);
		method.setViewUri("/main/treecascade");
		method.setVisible(false);//工具栏不可见

		DefaultNode<IExecutor> node=new DefaultNode<IExecutor>("执行器");
		method.setExecutors(node);
		List<IExecutor> list=new ArrayList<>();
		list.add(spring.getBean(TreeExecutor.class));//		private GridExecutor gridExecutor;
		node.setList(list);
		return method;
	}
	@Bean
	public DefaultMethod viewBean() {
		DefaultMethod method=new DefaultMethod();
		method.setCode("view");
		method.setName("查看数据");
		method.setValidation(false);
		method.setCurrentRow(true);
		method.setVisible(false);//工具栏不可见
		DefaultNode<IExecutor> node=new DefaultNode<IExecutor>("执行器");
		method.setExecutors(node);
		List<IExecutor> list=new ArrayList<>();
		node.setList(list);
		return method;
	}
	
	@Bean
	public DefaultMethod OutputExcelBean() {
		DefaultMethod method=new DefaultMethod();
		method.setCode("lingx_ouput_excel");
		method.setName("导出");
		method.setButtonType("success");
		method.setValidation(false);
		method.setCurrentRow(false);
		method.setIconCls("el-icon-download");
		DefaultNode<IExecutor> node=new DefaultNode<IExecutor>("执行器");
		method.setExecutors(node);
		List<IExecutor> list=new ArrayList<>();
		node.setList(list);
		return method;
	}
	@Bean
	public DefaultMethod comboBean() {
		DefaultMethod method=new DefaultMethod();
		method.setCode("combo");
		method.setName("列表数据");
		method.setValidation(false);
		method.setVisible(false);//工具栏不可见

		DefaultNode<IExecutor> node=new DefaultNode<IExecutor>("执行器");
		method.setExecutors(node);
		List<IExecutor> list=new ArrayList<>();
		list.add(spring.getBean(ComboExecutor.class));//		private GridExecutor gridExecutor;
		node.setList(list);
		return method;
	}
	@Bean
	public DefaultMethod getBean() {
		DefaultMethod method=new DefaultMethod();
		method.setCode("get");
		method.setName("单条记录");
		method.setValidation(false);
		method.setVisible(false);//工具栏不可见

		DefaultNode<IExecutor> node=new DefaultNode<IExecutor>("执行器");
		method.setExecutors(node);
		List<IExecutor> list=new ArrayList<>();
		list.add(spring.getBean(GetExecutor.class));//		private GridExecutor gridExecutor;
		node.setList(list);
		return method;
	}
}
